package com.lyf.scm.plan.domain.remote.bigdata.facade;

import com.lyf.scm.common.enums.ResponseMsg;
import com.lyf.scm.plan.domain.remote.bigdata.CprfCoreRemote;
import com.lyf.scm.plan.domain.remote.bigdata.dto.*;
import com.rome.arch.core.exception.RomeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * description:
 *
 * @author: haodong
 * @data: 2020/9/4 19:42
 */
@Slf4j
@Service
public class CprfCoreFacade {
    public static final String HALF_SUCCESS_CODE = "LYF00001";
    public static final String SUCCESS_CODE = "LYF00000";

    @Resource
    private CprfCoreRemote cprfCoreRemote;

    /**
     * 分页获取销售预测数据（周）
     *
     * @param bigDataGeneralQueryBaseDTO
     * @return {@link List< SalePredictDayDTO >}
     **/
    public List<SalePredictWeekDTO> getSalePredict(BigDataGeneralQueryBaseDTO bigDataGeneralQueryBaseDTO) {
        BigDataResponse<SalePredictWeekDTO> response = cprfCoreRemote.getSalePredict(bigDataGeneralQueryBaseDTO);
        if (!SUCCESS_CODE.equals(response.getCode()) && !HALF_SUCCESS_CODE.equals(response.getCode())) {
            throw new RomeException(ResponseMsg.FAIL_4001.getCode(), ResponseMsg.FAIL_4001.getMsg() + " , " + response.getMessage());
        }
        return response.getData().getList();
    }

    /**
     * 分页获取销售预测数据（日）
     *
     * @param bigDataGeneralQueryBaseDTO
     * @return {@link List< SalePredictDayDTO >}
     **/
    public List<SalePredictDayDTO> getDaySalePredict(BigDataGeneralQueryBaseDTO bigDataGeneralQueryBaseDTO) {
        BigDataResponse<SalePredictDayDTO> response = cprfCoreRemote.getDaySalePredict(bigDataGeneralQueryBaseDTO);
        if (!SUCCESS_CODE.equals(response.getCode()) && !HALF_SUCCESS_CODE.equals(response.getCode())) {
            throw new RomeException(ResponseMsg.FAIL_4000.getCode(), ResponseMsg.FAIL_4000.getMsg() + " , " + response.getMessage());
        }
        return response.getData().getList();
    }

    /**
     * 分页获取安全库存数据（日）
     *
     * @param bigDataGeneralQueryBaseDTO
     * @return {@link List< SalePredictDayDTO >}
     **/
    public List<SafetyStockDTO> getDaySafetyStock(BigDataGeneralQueryBaseDTO bigDataGeneralQueryBaseDTO) {
        BigDataResponse<SafetyStockDTO> response = cprfCoreRemote.getDaySafetyStock(bigDataGeneralQueryBaseDTO);
        if (!SUCCESS_CODE.equals(response.getCode()) && !HALF_SUCCESS_CODE.equals(response.getCode())) {
            throw new RomeException(ResponseMsg.FAIL_4002.getCode(), ResponseMsg.FAIL_4002.getMsg() + " , " + response.getMessage());
        }
        return response.getData().getList();
    }

    /**
     * 日补货预估结果查询
     *
     * @param bigDataGeneralQueryBaseDTO
     * @return {@link List< SalePredictDayDTO >}
     **/
    public List<BigDataGeneralInfoDTO> getDayPredictReplenishment(BigDataGeneralQueryBaseDTO bigDataGeneralQueryBaseDTO) {
        BigDataResponse<BigDataGeneralInfoDTO> response = cprfCoreRemote.getDayPredictReplenishment(bigDataGeneralQueryBaseDTO);
        if (!SUCCESS_CODE.equals(response.getCode()) && !HALF_SUCCESS_CODE.equals(response.getCode())) {
            throw new RomeException(ResponseMsg.FAIL_4003.getCode(), ResponseMsg.FAIL_4003.getMsg() + " , " + response.getMessage());
        }
        return response.getData().getList();
    }

    public List<TiSsStockResultDTO> thirteenWeekPredictSale(TiSsStockQueryDTO query) {
        log.info("查询13周销量预估结果入参：QueryBaseDTO:{}", query);
        BigDataResponse<TiSsStockResultDTO> response = cprfCoreRemote.thirteenWeekPredictSale(query);
        if (!SUCCESS_CODE.equals(response.getCode()) && !HALF_SUCCESS_CODE.equals(response.getCode())) {
            throw new RomeException(ResponseMsg.FAIL_4003.getCode(), ResponseMsg.FAIL_4003.getMsg() + " , " + response.getMessage());
        }
        return response.getData().getList();
    }
}
